extends Area2D

@export var move_speed = 300;

@export var type = 'gear';

@export var gear_speed = 90;
@export var gear_fractionFactor = 3;
@export var gear_radius = 60;
var gear_spd_fix = false;

@export var collided_gears = [];
var collider_obj = false;
var sprite_obj = false;
var grab_obj = false;

var self_c = Color.WHITE;

func _ready():
	sprite_obj = get_node('gear_spr');
	collider_obj = get_node('gear_collision');
	grab_obj = get_node('grab');
	collider_obj.shape = CircleShape2D.new();
	resize(gear_radius, false);

func _process(delta):
	var gd;
	gd = preload('res://scripts/gear/move.gd');
	gd.move(self, delta)
	gd = preload('res://scripts/gear/collision.gd');
	gd.collision(self, delta)
	if(typeof(gear_spd_fix) != TYPE_BOOL):
		gear_speed = gear_spd_fix;

func _draw():
	var draw_gd = preload('res://scripts/gear/draw.gd');
	var draws = draw_gd.draw(self);
	for i in draws['lines']:
		draw_line.callv(i);
	for i in draws['arcs']:
		draw_arc.callv(i);

	
func _input(event):
	var input_gd = preload('res://scripts/gear/input.gd');
	input_gd.input(self, event, get_local_mouse_position())

func resize(x, isrelative = true):
	var _self = self;
	if(isrelative): _self.gear_radius += x;
	else: _self.gear_radius = x;
	
	#var gear_radius = _self.gear_radius;
	_self.collider_obj.shape.radius = gear_radius
	var spr = _self.sprite_obj;
	var t = gear_radius / spr.get_meta('size_div_scale', 88.496);
	spr.scale = Vector2(t, t); 

func redraw():
	queue_redraw();
	if(type == 'grab'): grab_obj.queue_redraw();
